<?php

function __autoload($class_name) {

    $fullclasspath = "";
    $suffix = "";
    if (!file_exists('../alania21/inc/' . $fullclasspath . $class_name . ".php")) {
        if (!file_exists('../alania21/inc/' . $fullclasspath . $class_name . ".class.php")) {
            if (file_exists('../alania21/inc/utility/' . $class_name . ".class.php")) {
                $fullclasspath = "utility/";
                $suffix = ".class";
            }
        } else {
            $suffix = ".class";
        }
    }
    //echo '../alania21/inc/' . $fullclasspath . $class_name . $suffix . '.php<br />';
    require_once '../alania21/inc/' . $fullclasspath . $class_name . $suffix . '.php';
}

if (!isset($_POST['preubaselect'])) {
    $db = new connection();
    $op = "[";
    foreach (AlaniaContenidosModel::selectAll($db->db) as $value) {
        $op.='{"optionValue": ' . $value->getId() . ', "optionDisplay": "' . $value->getNombre() . '"},';
    }
    $op = substr($op, 0, -1) . "]";
    echo $op;
} else {
    $accion = $_POST['preubaselect'];
require_once 'inc/fire/FirePHP.class.php';
    $firephp= FirePHP::getInstance(true);
    $firephp->log($accion);
    $page = new Template();
    $page->setID(intval($accion));
    require_once 'inc/fire/FirePHP.class.php';
    $firephp= new FirePHP();
    $firephp->log($page->getText());
    preg_match_all('/(\[\[@)(?<name>(?:[a-z][a-z0-9_]*))(\]\])/is', $page->getText(), $matches);
    if (array_key_exists('name', $matches)) {

        if (count($matches['name'])) {
            $page->set($matches['name'][0], '{"#text":{"hijos":[],"0":"[@' . $matches['name'][0] . ']","attributes":""}}');
        }
    }
    $page->setText();



    echo $page->outputHTML();
}
?>
